package com.atguigu.eduservice.controller.front;

import com.atguigu.commonutils.Result;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 讲师的前台接口
 *
 * @author zr
 */
@RestController
@Api(tags = "讲师数据")
@RequestMapping("/edu/service/front/teacher")
//@CrossOrigin
public class TeacherFrontController {
    @Autowired
    private EduTeacherService eduTeacherService;
    @Autowired
    private EduCourseService eduCourseService;

    @ApiOperation(value = "分页讲师列表")
    @GetMapping("getTeacherFrontList/{page}/{limit}")
    public Result getTeacherFrontList(
            @ApiParam(name = "limit", value = "当前页码", required = true)
            @PathVariable long limit,
            @ApiParam(name = "page", value = "每页记录数", required = true)
            @PathVariable long page) {
        Page<EduTeacher> teacherPage = new Page<>(page, limit);
        Map<String, Object> teacherFrontList = eduTeacherService.getTeacherFrontList(teacherPage);
        return Result.ok(teacherFrontList);
    }

    @ApiOperation(value = "根据ID查询讲师")
    @GetMapping("getTeacherFrontInfo/{teacherId}")
    public Result getTeacherFrontInfo(
            @ApiParam(name = "teacherId", value = "讲师ID", required = true)
            @PathVariable String teacherId) {
        // 根据讲师Id查询讲师基本信息
        EduTeacher eduTeacher = eduTeacherService.getById(teacherId);
        // 根据讲师Id查询讲师所讲课程
        List<EduCourse> eduCourseList = eduCourseService.findCourseInfoById(teacherId);
        Map<Object,Object> map=new HashMap<>();
        map.put("teacher", eduTeacher);
        map.put("courseList", eduCourseList);
        return Result.ok(map);
    }
}
